home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDElapsedTrack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.0 KB  |  106 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDElapsedTrack - An XFCN to report elapsed time on disc
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDElapsedTrack.c
  11.     link -sn Main=CDElapsedTrack -sn STDIO=CDElapsedTrack ∂
  12.          -sn INTENV=CDElapsedTrack -rt XFCN=42 ∂
  13.          -m CDElapsedTrack CDElapsedTrack.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27.  
  28. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  29.  
  30.  
  31. /************************************************************************
  32.  *
  33.  *  Function:        CDElapsedTrack
  34.  *
  35.  *  Purpose:        return the elapsed time on this disc.
  36.  *
  37.  *  Returns:        either 0, or an error
  38.  *                    if it's a negative number, it's an error
  39.  *
  40.  *  Side Effects:
  41.  *
  42.  *  Description:    We need no parameters.
  43.  *                    Get the ioRefNum that we got from previously calling
  44.  *                    CDOpen() from its famous global name
  45.  *                    call the driver with a READQ call to find out
  46.  *                    how absolute minute, second, block elapsed.
  47.  *
  48.  ************************************************************************/
  49. pascal void
  50. CDElapsedTrack(paramPtr)
  51. XCmdBlockPtr    paramPtr;
  52. {
  53.     Str31    returnString;
  54.     OSErr    result;
  55.     short    ioRefNum;
  56.     Handle    refHandle;
  57.     long    Elapsed[4];    /* minute, second, block */
  58.     long    currentMinute, currentSecond, currentBlock;
  59.     long    startMinute, startSecond, startBlock;
  60.     
  61.     /* Must be no parameters */
  62.     if ((paramPtr->paramCount) != 0)
  63.     {
  64.         /* Report error in parameters by returning -1 */
  65.         NumToStr(paramPtr, (long) -1, &returnString);
  66.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  67.         return;
  68.     }
  69.     
  70.     /* Get the global ioRefNum and convert it. */
  71.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  72.     ioRefNum = atoi(*(refHandle));
  73.     DisposHandle(refHandle);
  74.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  75.     
  76.     
  77.     result = ReadQ(ioRefNum, &Elapsed[0], ¤tMinute, ¤tSecond, ¤tBlock);
  78.     
  79.     if (result == noErr)
  80.         result = TrackStart(ioRefNum, Elapsed[0], &startMinute, &startSecond, &startBlock);
  81.     
  82.     if (result == noErr)
  83.     {
  84.         TimeDiff(&Elapsed[1], &Elapsed[2], &Elapsed[3],
  85.                  currentMinute, currentSecond, currentBlock,
  86.                  startMinute, startSecond, startBlock);
  87.     }
  88.  
  89.     if (result == noErr)
  90.     {
  91.         /* convert each value to a string, concatenate, & return. */
  92.         FormatString(&returnString, Elapsed, 4);
  93.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  94.     }
  95.     else
  96.     {
  97.         /* We got an error. Convert result to string & return it as error */
  98.         NumToStr(paramPtr, (long) result, &returnString);
  99.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  100.     }
  101. }
  102.  
  103.  
  104. /* C routines for HyperCard callbacks */
  105. #include <XCmdGlue.inc.c>
  106.